package com.graphcoloring;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GraphInputData {
	private int vertexNumber;
	private int edgeNumber;

	private Map<Integer, List<Integer>> connectedEdges = new HashMap<Integer, List<Integer>>();
	private List<Integer[]> edgeList = new ArrayList<Integer[]>();

	public GraphInputData(String inputFilename) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFilename)));

		String s = null;

		while ((s = reader.readLine()) != null) {
			String[] data = s.split(" ");
			if (s.startsWith("p")) {
				vertexNumber = Integer.valueOf(data[2]);
				edgeNumber = Integer.valueOf(data[3]);

				for (int i = 0; i < vertexNumber; i++)
					connectedEdges.put(i, new ArrayList<Integer>());
			}
			if (s.startsWith("e")) {
				int edge1 = Integer.valueOf(data[1]) - 1;
				int edge2 = Integer.valueOf(data[2]) - 1;
				
				connectedEdges.get(edge1).add(edge2);
				connectedEdges.get(edge2).add(edge1);
				edgeList.add(new Integer[] { edge1, edge2 });
			}
		}
		reader.close();
	}

	public int getVertexNumber() {
		return vertexNumber;
	}

	public int getEdgeNumber() {
		return edgeNumber;
	}

	public Map<Integer, List<Integer>> getConnectedEdges() {
		return connectedEdges;
	}
	
	public List<Integer[]> getEdgeList() {
		return edgeList;
	}
}
